{extend name="public/base" /} {block name="css"}
<link rel="stylesheet" href="__INDEX__/css/clothes-create.css"> 
{/block}
{block name="container"}

<div class="panel-body panel-body-nopadding" style="padding-bottom:50px;">
    <div class="inforMain">添加编码</div>

    <form class="form-horizontal form-bordered" id="submitForm" action="" method="post" > 
        <div class="form-group" style="padding-left: 2%">
            <label class="col-sm-1 control-label"><span>*</span>商品名称：</label>
            <div class="col-sm-2"><input type="text" value="{$data['name'] ?? ''}"   class="shangpingName" name="name" id="" required></div>

            <label class="col-sm-1 control-label"><span>*</span>面料编号：</label>
            <div class="col-sm-2"><input type="text" value="{$data['ml_num'] ?? ''}"   class="shuru" name="ml_num" id="ml_num" required></div>

            <label class="col-sm-1 control-label"><span>*</span>面料属性：</label>
            <div class="col-sm-2" >
                <input type="text" value="{$data['ml_style'] ?? ''}" id="ml_style"   name="ml_style" required>
            </div>
        </div>

        <div class="form-group" style="padding-left: 2%">
            <label class="col-sm-1 control-label"><span>*</span>性&emsp;&emsp;别：</label>
            <div class="col-sm-2" >
                <input type="radio" value="8" name="sex" style="width: 10%;text-align: center;line-height: 30px;float: left" required ><span class="sexBox">男</span>
                <input type="radio" value="6" name="sex" style="width: 10%;margin-left: 30px;text-align: center;line-height: 30px;float: left;" required ><span class="sexBox">女</span>
            </div>

            <label class="col-sm-1 control-label"><span>*</span>年&emsp;&emsp;份：</label>
            <div class="col-sm-2" >
                <input type="text" style="background: #fff;"  class="form-control" placeholder="年份" name="year" value="" id="year"  readonly>
            </div>
            
            <label class="col-sm-1 control-label"><span>*</span>季&emsp;&emsp;节：</label>
            <div class="col-sm-2" >
                <select name="season" id="jijie"  >
                    <option value="1">春季</option>
                    <option value="2">夏季</option>
                    <option value="3">秋季</option>
                    <option value="4">冬季</option>
                </select>
            </div>
        </div>

        <div class="form-group" style="padding-left: 2%">
            <label class="col-sm-1 control-label"><span>*</span>品&emsp;&emsp;类：</label>
            <div class="col-sm-2">
                <select name="category" id="pinlei" >
                    <option value="-1" >请选择品类</option>
                    {volist name="category" id="vo"}
                    <option value="{$vo.id}">{$vo.value}</option>
                    {/volist}
                </select>
            </div>
            
            <label class="col-sm-1 control-label"><span>*</span>号&emsp;&emsp;型：</label>
            <div class="col-sm-2">
                <select name="size" id="haoxing"  >
                    <option value="-1">请选择号型</option>
                    {volist name="size" id="o"}
                    <option value="{$o.id}">{$o.value}</option>
                    {/volist}
                </select>
            </div>

            <label class="col-sm-1 control-label"><span>*</span>颜&emsp;&emsp;色：</label>
            <div class="col-sm-2">
                <select name="color" id="yanse"  >
                    <option value="-1">请选择颜色</option>
                    {volist name="color" id="v"}
                    <option value="{$v.id}">{$v.value}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="form-group" style="padding-left: 2%">
            <label class="col-sm-1 control-label"><span>*</span>价&emsp;&emsp;格：</label>
            <div class="col-sm-2"><input type="text" class="form-control" placeholder="价格" name="price" value="{$data.price ?? ''}"    id="price" required style="background: white;"></div>
            
            <label class="col-sm-1 control-label"><span>*</span>数&emsp;&emsp;量：</label>
            <div class="col-sm-2"><input type="text" value="{$data['num'] ?? ''}"   class="" name="num" id="" required></div>
        
		    <label class="col-sm-1 control-label"><span>*</span>款式编号：</label>
            <div class="col-sm-2"><input type="text" value="{$data['kuanshi'] ?? ''}"  class="" name="kuanshi" id="" required></div>
		</div>
        
    </div>


    <div class="panel-footer" style="padding-top: 50px;background: #fff;border-top:0px;">
        <div class="row">
            <div class="col-sm-6 col-sm-offset-4">
                <input type="hidden" name="id" value="">
                <input type="hidden" name="code" id="code">
                <button type="submit" class="btn btn-primary" style="margin:0 auto" id="createMa"> 点此生成成衣编号</button>
                <div id="maBox"></div>
            </div>
        </div>
    </div>
    <!-- panel-footer -->
</form>
</div>
{/block} 
{block name="js"}
<script>
    $().ready(function(){
        var myDate = new Date();
        var y = myDate.getFullYear();  //获取当前年份
        $('#year').val(y);
        $("[name='category']").find("[value='{$data.category ?? '1'}']").attr("selected", true);
        $("[name='sex'][value='{$data.sex ?? '8'}']").attr("checked", true);
        $("[name='size']").find("[value='{$data.size ?? '1'}']").attr("selected", true);
        $("[name='color']").find("[value='{$data.color ?? '1'}']").attr("selected", true);
        $("[name='season']").find("[value='{$data.season ?? '1'}']").attr("selected", true);
        $('#createMa').click(function(){
            var year = $('#year').val();
            var jijie = $('#jijie').val();
            var price = $('#price').val();
            var pinlei = $('#pinlei').val();
            var yanse = $('#yanse').val();
            var haoxing = $('#haoxing').val();
            var ml_num = $('#ml_num').val();
            var sex = $('input:radio[name="sex"]:checked').val();
            if(year == '' || jijie == '' || price == "" || pinlei == '-1' || yanse == '-1' || haoxing =='-1' || ml_num == '')
            {
                return false;
            }
            if(pinlei.length<2){
                pinlei = '0'+pinlei;
            }
            if(yanse.length<2){
                yanse = '0'+yanse;
            }  
            if(haoxing.length<2){
                haoxing = '0'+haoxing;
            }  
            var num = year.substring(3);
            var code = num+''+jijie+''+sex+''+pinlei+''+yanse+''+haoxing+''+ml_num;
            $('#code').val(code);
            $('#submitForm').submit();
            // $.post('{:url("index/clothes/ajaxAddCode")}', {year:year, season:jijie,price:price,category:pinlei,color:yanse,sex:sex,size:haoxing,ml_num:ml_num,code:code}, function(data) {
            //     if(data == 1){
            //     var url = '/code.php?text='+code;
            //     alert(url);
            //     var html = `<img src="`+url+`" width="120px">`;
                
            //     document.getElementById('maBox').innerHTML = html;   
            //     }
            // });
        })
        
    })

</script>

{/block}